package core

import (
	"fmt"
	"log"

	"github.com/fatih/color"
)

type Logger struct {
	Message string
	Fields  map[string]interface{}
}

func (l *Logger) WithFields(fields map[string]interface{}) *Logger {
	l.Fields = fields
	return l
}

func (l *Logger) Info(message string) {
	var newLog string
	newLog = "· [INFO]\n"
	newLog += message
	for k, v := range l.Fields {
		newLog += fmt.Sprintf(" [%s:%v]", k, v)
	}
	newLog += "\n\n"
	l.Message = newLog
	log.Printf(l.Message)
}

func (l *Logger) Warning(message string) {
	var newLog string
	newLog = "· [WARNING]\n"
	newLog += message
	for k, v := range l.Fields {
		newLog += fmt.Sprintf(" [%s:%v]", k, v)
	}
	newLog += "\n\n"
	l.Message = newLog
	log.Print(color.YellowString(l.Message))
}

func (l *Logger) Error(message string) {
	var newLog string
	newLog = "[ERROR]\n"
	newLog += message
	for k, v := range l.Fields {
		newLog += fmt.Sprintf(" [%s:%v]", k, v)
	}
	newLog += "\n\n"
	l.Message = newLog
	log.Print(color.RedString(l.Message))
}

var MyLogger = &Logger{}

type LogFields map[string]interface{}
